package com.chinackts.auth.model;

import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Lianhong
 * @since 2025/8/6
 * 代理IP （巨量）
 */
@Data
public class ProxyIP_JL implements Serializable {
    //{"code":200,"msg":"成功","data":{"count":1,"filter_count":1,"surplus_quantity":990,"proxy_list":[{"ip":"103.43.135.4","ip_remain":179,"port":"11121","real_ip":"39.158.51.3"}]}}
    private String code;
    private String msg;
    private ResponseData data;

    public ProxyIP convert() {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime futureTime = now.plusSeconds(180);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedTime = futureTime.format(formatter);
        return new ProxyIP(
                ProxyType.JL,
                this,
                this.data.proxy_list.stream().map(item -> new ProxyIP.Item(item.ip, item.port, formattedTime)).collect(Collectors.toList())
        );
    }

    @Data
    public static class ResponseData implements Serializable {

        private int count;
        private int filter_count;
        private int surplus_quantity;
        private List<ItemData> proxy_list;

        @Data
        public static class ItemData implements Serializable {

            private String ip;
            private int port;
            private int ip_remain;
            private String real_ip;
        }
    }
}
